package com.atguigu.lease.common.sms;


import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @Author: shenhao
 * @CreatTime: 2024/9/12 11:28
 * @Version: 1.0
 */
@SpringBootConfiguration
@EnableConfigurationProperties(AliyunSMSProperties.class)
public class AliyunSmsConfiguration {
    @Autowired
    private AliyunSMSProperties aliyunSMSProperties;
    @Bean
    public Client smsClient(){
        Config config = new Config();
        config.setAccessKeyId(aliyunSMSProperties.getAccessKeyId());
        config.setAccessKeySecret(aliyunSMSProperties.getAccessKeySecret());
        config.setEndpoint(aliyunSMSProperties.getEndpoint());
        try {
            return new Client(config);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
